import ScrollBarLayout from '@/components/ScrollBarLayout';
import Cls from 'classnames';
import { useContext, useEffect } from 'react';
import { IClarificationControllerContext } from '../../common/useOAContext';
import { Input, Spin } from 'antd';
import { useDescriptions, Descriptions } from '@/components/Descriptions';
import { formatDecimal } from '../../../Acommon';
import { TagSelectNew as TagSelect } from '@/components/TagSelectNew';
import moment from 'moment';
import { downloadTemplate, getFileNameByPath, getUserDepName, getUserID, getUserName, newGetFileNameNotType } from '@/utils';
import MyIcon from '@/components/MyIcon';

export const DetailInfoCenterViewMainOA: React.FC = () => {
  /** 引入上下文 */
  const { styleFixCls, infoObj } = useContext(IClarificationControllerContext);

  /** 初始化 */
  useEffect(() => {
    if (infoObj?.id) {
      setFieldsValue({
        ...infoObj,
        bidClearTime: infoObj?.bidClearTime ? moment(infoObj?.bidClearTime) : null,
        bidBeginTime: infoObj?.bidBeginTime ? moment(infoObj?.bidBeginTime) : null,
      });
    }
  }, [infoObj]);

  /** 表格表单配置信息 */
  const [config, { setFieldsValue }] = useDescriptions({
    labelWidth: 200,
    schemas: [
      {
        label: '一、项目信息',
        field: 'title',
        component: 'Title',
      },
      {
        label: '采购项目名称',
        field: 'purchProjectName',
        component: 'Input',
        disabled: true,
      },
      {
        label: '流水单号',
        field: 'clarifyCode',
        component: 'Input',
        disabled: true,
      },
      {
        label: '澄清提出日期',
        field: 'bidBeginTime',
        component: 'DatePicker',
        placeholder: '--',
        disabled: true,
        required: true,
        message: '请选择澄清提出日期',
      },
      {
        label: '澄清截止日期',
        field: 'bidClearTime',
        component: 'DatePicker',
        placeholder: '--',
        disabled: true,
        required: true,
        message: '请暂存招标公告澄清截止日期',
      },
      {
        label: '联系人',
        field: 'dutyerName',
        component: 'Input',
        placeholder: '请输入联系人',
        required: true,
        message: '请输入联系人',
        disabled: true,
      },
      {
        label: '联系电话',
        field: 'dutyPhone',
        component: 'Input',
        placeholder: '请输入联系电话',
        required: true,
        message: '请输入联系电话',
        disabled: true,
      },
      {
        label: '承办部门',
        field: 'dutyDepartmentName',
        component: 'Input',
        placeholder: '请输入承办部门',
        required: true,
        message: '请输入承办部门',
        disabled: true,
      },
      {
        label: '是否影响投标文件编制',
        field: 'effectFlag',
        component: 'Render',
        required: true,
        disabled: true,
        slotRender: (text: string = '0') => {
          return (
            <TagSelect
              colSpan={12}
              formLabel={''}
              formName={'effectFlag'}
              radioDisabled={true}
              defalultKeys={Number(text)}
              radioList={[
                {
                  value: 1,
                  name: '是',
                },
                {
                  value: 0,
                  name: '否',
                },
              ]}
            />
          );
        },
      },
      {
        label: '二、澄清说明',
        field: 'title',
        component: 'Title',
      },
      {
        label: '变更前内容', // 未找到
        field: 'preContent',
        component: 'InputTextArea',
        placeholder: '--',
        maxLength: 800,
        allowClear: true,
        autoSize: { minRows: 5, maxRows: 7 },
        showCount: true,
        colSpan: 2,
        disabled: true,
        required: true,
        message: '请输入变更前内容',
      },
      {
        label: '变更后内容', // 未找到
        field: 'afterContent',
        component: 'InputTextArea',
        placeholder: '--',
        maxLength: 800,
        allowClear: true,
        autoSize: { minRows: 5, maxRows: 7 },
        showCount: true,
        colSpan: 2,
        disabled: true,
        required: true,
        message: '请输入变更后内容',
      },
      {
        label: '澄清附件',
        field: 'attachURL',
        component: 'Render',
        colSpan: 2,
        required: true,
        message: '请上传澄清附件',
        slotRender: (text: string, record: Record<string, any>) => {
          const fileName = text ? getFileNameByPath(text) : '';
          return (
            <div style={{ width: '100%', display: 'flex', justifyContent: 'space-between', padding: 10 }}>
              {fileName ? (
                <>
                  <a
                    onClick={() => {
                      downloadTemplate('/purchaseSourceClarifyController/downloadFile', fileName, record?.attachURL, () => {});
                    }}
                  >
                    {/* {fileName} */}
                    <MyIcon type="icon-file-text-fill" />
                    &nbsp;
                    {newGetFileNameNotType(fileName, 7)}
                  </a>
                </>
              ) : (
                <Input disabled={true} placeholder="--" />
              )}
            </div>
          );
        },
      },
    ],
  });

  return (
    <>
      <div className="commonTabsBodyDom">
        <div className={Cls('tabsBodyInfoDom', `${styleFixCls}updateFormBox`)}>
          <ScrollBarLayout style={{ padding: '5px 100px' }}>
            <Spin spinning={false}>
              <Descriptions config={config} />
            </Spin>
          </ScrollBarLayout>
        </div>
      </div>
    </>
  );
};
